//
//  FCImgChoicedTableViewCell.m
//  Pods
//
//  Created by WJC on 2021/1/7.
//

#import "FCImgChoicedTableViewCell.h"
#import "WJCDefine.h"
#import "NSMutableAttributedString+FCReplaceString.h""
@interface FCImgChoicedTableViewCell()<FCImageChoiceDelegate>
@end
@implementation FCImgChoicedTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        createCommonLabel(titleL, font15, HEXC(0x232323));
        self.topLabel.x=16;
        self.topLabel = titleL;
        [self.contentView addSubview:self.topLabel];
        
        createCommonLabel(countL, font14, HEXC(0x646262));
        self.countLabel = countL;
        [self.contentView addSubview:self.countLabel];
        self.choiceImg = [[FCImageChoiceShow alloc] initWithFrame:CGRectMake(16, 16, WJCScreenW-32, 120) andChoiceArr:nil andMaxShowPerCount:3];
        self.choiceImg.isShowCloseBtn = YES;
        self.choiceImg.delegate = self;
        [self.contentView addSubview:self.choiceImg];
        
    }
    return self;
}
-(void)setSift:(WJCSiftModel *)sift{
    _sift = sift;
    CGFloat height=4;
    if (sift.Name.length>0) {
        self.topLabel.text =sift.Name;
        if(sift.choiced){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",sift.Name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            self.topLabel.attributedText=string;
        }
        [self.countLabel sizeToFit];
        self.topLabel.x = 16;
        self.topLabel.y = 8;
        height += self.topLabel.bottom;
    }
    if (sift.maxPerCount>0) {
        self.choiceImg.maxShowToCount = sift.maxPerCount;
        
    }
    if (sift.maxCount>0) {
        self.choiceImg.maxChoiceImage = sift.maxCount;
        self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld",self.choiceImg.imageArr.count,self.choiceImg.maxChoiceImage];
        [self.countLabel sizeToFit];
        self.countLabel.x = self.width-16-self.countLabel.width;
        self.countLabel.y = 10;
        if (height==16) {
            height += self.countLabel.bottom;
        }
      
    }else{
        
        self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld",self.choiceImg.imageArr.count,self.choiceImg.maxChoiceImage];
        [self.countLabel sizeToFit];
        self.countLabel.y = 10;
        self.choiceImg.maxChoiceImage =9;
        if (height==16) {
            height += self.countLabel.bottom;
        }
        self.countLabel.right = WJCScreenW-16;
    }
    if (sift.others&&[sift.others isKindOfClass:[NSArray class]]) {
        self.choiceImg.imageArr = sift.others;
    }
    self.choiceImg.y = height;
    [self.choiceImg refreshWithNoDelegateImage];
}
-(void)setObj:(tableObj *)obj{
    _obj = obj;
    CGFloat height=4;
    if (obj.name.length>0) {
        self.topLabel.text =obj.name;
        [self.countLabel sizeToFit];
        self.topLabel.x = 16;
        self.topLabel.y = 8;
        height += self.topLabel.bottom;
    }
    if (obj.maxPerCount>0) {
        self.choiceImg.maxShowToCount = obj.maxPerCount;
        
    }
    if (obj.maxCount>0) {
        self.choiceImg.maxChoiceImage = obj.maxCount;
        self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld",self.choiceImg.imageArr.count,self.choiceImg.maxChoiceImage];
        [self.countLabel sizeToFit];
        self.countLabel.x = WJCScreenW-16-self.countLabel.width;
        self.countLabel.y = 10;
        if (height==16) {
            height += self.countLabel.bottom;
        }
      
    }else{
        
        self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld",self.choiceImg.imageArr.count,self.choiceImg.maxChoiceImage];
        [self.countLabel sizeToFit];
        self.countLabel.y = 10;
        self.choiceImg.maxChoiceImage =9;
        if (height==16) {
            height += self.countLabel.bottom;
        }
        self.countLabel.right = WJCScreenW-16;
    }
    if (obj.other&&[obj.other isKindOfClass:[NSArray class]]) {
        self.choiceImg.imageArr = obj.other;
    }
    self.choiceImg.y = height;
    [self.choiceImg refreshWithNoDelegateImage];
    
}
-(void)FCImageChoiceImage:(FCImageChoiceShow *)choiceView{
    self.countLabel.text = [NSString stringWithFormat:@"%ld/%ld",self.choiceImg.imageArr.count,self.choiceImg.maxChoiceImage];
    CGFloat height=self.countLabel.bottom+16+choiceView.height+16;
    self.countLabel.right = WJCScreenW-16;
    if (self.obj) {
        self.obj.other = choiceView.imageArr;
        self.obj.height =height;
    }else if(self.sift){
        self.sift.others = choiceView.imageArr;
        self.sift.height =height;
    }
    
    if (self.parentTableView&&self.index) {
        [self.parentTableView reloadRowsAtIndexPaths:@[self.index] withRowAnimation:UITableViewRowAnimationFade];
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
